from functools import wraps
from flask_login import current_user
from flask import redirect, url_for
from functools import wraps

def admin_required(func):
    @wraps(func)
    def decorated_view(*args, **kwargs):
        if current_user.user_permission != "admin":       
            return redirect(url_for("user.index"))
        return func(*args, **kwargs)
    return decorated_view


def user_required(func):
    @wraps(func)
    def decorated_view(*args, **kwargs):
        if current_user.user_permission != "user":       
            return redirect(url_for("admin.index"))
        return func(*args, **kwargs)
    return decorated_view